// Copyright Gary Evans 2006.

using System;

using Tao.OpenGl;

using Taumuon.Jabuka.Physics;
using System.Drawing;

namespace Taumuon.Jabuka.MainApp
{
    class Axes : IDrawable
    {
        #region Object Lifetime

        /// <summary>
        /// Construct a drawable set of axes, aligned with the
        ///  world coordinate system.
        /// </summary>
        /// <param name="eulerRigidBody">
        /// The rigid body that is used to obtain the
        ///  axes's location.
        /// </param>
        /// <exception cref="ArgumentNullException"/>
        /// <remarks>
        /// Blue is aligned with the x axis,
        /// Green with the y axis and 
        /// Red with the z axis
        /// </remarks>
        public Axes(EulerRigidBody eulerRigidBody)
        {
            if (eulerRigidBody == null)
            {
                throw new ArgumentNullException("eulerRigidBody");
            }
            this.eulerRigidBody = eulerRigidBody;
        }

        #endregion Object Lifetime

        #region Member Variables

        private EulerRigidBody eulerRigidBody = null;

        #endregion Member Variables

        public int axisSize
        {
            get
            {
                return 25;
            }
        }
        public void Draw()
        {
            Gl.glPushMatrix();
            Gl.glTranslated(eulerRigidBody.Location.X+eulerRigidBody.ScreenTranslate.X,
                eulerRigidBody.Location.Y+eulerRigidBody.ScreenTranslate.Y, 
                eulerRigidBody.Location.Z+eulerRigidBody.ScreenTranslate.Z);

         //   const float axisSize = 25.0f;

            // draw a red line along the z-axis
            Gl.glColor3f(1.0f, 0.0f, 0.0f);
            Gl.glBegin(Gl.GL_LINES);
            Gl.glVertex3f(0.0f, 0.0f, -axisSize);
            Gl.glVertex3f(0.0f, 0.0f, axisSize);
            Gl.glEnd();

            // draw a green line along the y-axis
            Gl.glColor3f(0.0f, 1.0f, 0.0f);
            Gl.glBegin(Gl.GL_LINES);
            Gl.glVertex3f(0.0f, -axisSize, 0.0f);
            Gl.glVertex3f(0.0f, axisSize, 0.0f);
            Gl.glEnd();

            // draw a blue line along the x-axis
            Gl.glColor3f(0.0f, 0.0f, 1.0f);
            Gl.glBegin(Gl.GL_LINES);
            Gl.glVertex3f(-axisSize, 0.0f, 0.0f);
            Gl.glVertex3f(axisSize, 0.0f, 0.0f);
            Gl.glEnd();

            Gl.glPopMatrix();
        }

        #region IDrawable Members


        public System.Drawing.Rectangle DrawSizeRectangle()
        {
            return new Rectangle((int)eulerRigidBody.ScreenCoordinate.X,
                (int)eulerRigidBody.ScreenCoordinate.Y, axisSize, axisSize);
            //throw new NotImplementedException();
        }

        #endregion
    }
}
